#pragma once

/// <summary>
/// d3dApp - Creates and initialises the application window and d3d settings
/// Forms the basis of the CCDemo application
/// <summary>

#include <Windows.h>
#include <D3D11.h>
#include <D3DX11.h>
#include <string>

#include "d3dUtil.h"
#include "GameTimer.h"

class D3DApp
{
public:
	D3DApp(HINSTANCE hInstance);
	virtual ~D3DApp();

	HINSTANCE		AppInst() const;
	HWND			MainWnd() const;
	float			AspectRatio() const;
	int				ScreenWidth() const;
	int				ScreenHeight() const;

	int Run();
	virtual void Shutdown();

	// Framework methods.
	virtual bool Init();
	virtual void OnResize();
	virtual void UpdateScene(float dt) = 0;
	virtual void DrawScene() = 0;
	virtual LRESULT MsgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

	// Convenience overrides for handling mouse input.
	virtual void OnMouseDown(WPARAM btnState, int x, int y) { }
	virtual void OnMouseUp(WPARAM btnState, int x, int y)	{ }
	virtual void OnMouseMove(WPARAM btnState, int x, int y) { }

protected:
	bool InitMainWindow();
	bool InitDirect3D();

	void CalculateFrameStats();

protected:
	HINSTANCE				mhAppInst;
	HWND					mhMainWnd;
	bool					mAppPaused;
	bool					mMinimized;
	bool					mMaximized;
	bool					mResizing;
	UINT					m4xMsaaQuality;

	GameTimer				mTimer;

	ID3D11Device*			md3dDevice;
	ID3D11DeviceContext*	md3dImmediateContext;
	IDXGISwapChain*			mSwapChain;
	ID3D11Texture2D*		mDepthStencilBuffer;
	ID3D11RenderTargetView*	mRenderTargetView;
	ID3D11DepthStencilView*	mDepthStencilView;
	D3D11_VIEWPORT			mScreenViewport;

	// Derived class should set these in derived constructor to customize starting values.
	std::wstring			mMainWndCaption;
	D3D_DRIVER_TYPE			md3dDriverType;
	D3D_FEATURE_LEVEL		mFeatureLevel;
	int						mClientWidth;
	int						mClientHeight;
	bool					mEnable4xMsaa;
};